/**
 * zoneland.net Inc.
 * Copyright (c) 2002-2013 All Rights Reserved.
 */
package net.zoneland.knowledge.enums;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * 返回对象类型.
 * @author Pbody
 * 22:04 2020/3/15
 */
public enum TypeEnum {
    /**
     * 文本.
     */
    TEXT("text", "文本"),
    /**
     * 对象.
     */
    OBJECT("object", "对象"),
    /**
     * 列表.
     */
    LIST("list", "列表"),
    /**
     * 定制页面列表.
     */
    CUSTOM_PAGE_LIST("customPageList", "定制页面列表");

    private String value;
    private String name;

    TypeEnum(final String value, final String name) {
        this.name = name;
        this.value = value;
    }

    /**
     * Gets the value of value.
     *
     * @return the value of value
     */
    public String getValue() {
        return value;
    }

    /**
     * Gets the value of name.
     *
     * @return the value of name
     */
    public String getName() {
        return name;
    }

    public static String getNameByValue(final String value) {
        return Optional.ofNullable(
                Stream.of(TypeEnum.values())
                        .filter(x -> x.getValue().equalsIgnoreCase(value))
                        .findFirst().orElse(null)
        ).map(TypeEnum::getName).orElse(null);
    }
}
